package crawler.douban;

import constant.DBConstant;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;

/**
 * 豆瓣图书
 * USER: lintc 【lintiancong@zhuojianchina.com】
 * DATE: 2017-09-21 14:27
 */
public class Book {

    public static Movie newBook(Element element) {
        Movie movie = new Movie();
        movie.setName(element.select(".title>a").text());
        movie.setUrl(element.select(".title>a").attr("href"));
        movie.setId(movie.getMovieId(movie.getUrl()));
        movie.setCommentCount(Teleplay.getCommentCount(element));
        movie.setStartLevel(Float.parseFloat(element.select(".rating>.rating_nums").text()));
        return movie;
    }

    public static void main(String[] args) throws IOException {
        String url = DBConstant.DB_BOOK_LIST_URL.replace("START_NUM", "0");
        Document doc = Jsoup.connect(url).get();
        Elements elements = doc.select(".doulist-item");
        for (Element element : elements) {
            System.out.println(newBook(element));
        }
    }
}
